//
//  ActionSheetViewController.m
//  CarTown
//
//  Created by xionghao on 15/8/7.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "ActionSheetViewController.h"

@interface ActionSheetViewController ()
@property (nonatomic,strong) NSMutableArray *array;
@end

@implementation ActionSheetViewController
-(instancetype)initWithTitle:(NSString *)title delegate:(id<ActionSheetDelegate>)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSArray *)array{
    
    if (self=[super init]) {
        self.view.frame=CGRectMake(0, 0, XHScreenwidth, XHScreenheight);
        self.view.backgroundColor=[UIColor clearColor];
        [self initOhterButton:title cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle otherButtonTitles:array];
        
    }
    return self;
}
-(NSMutableArray *)array{
    if ( _array==nil) {
        _array=[NSMutableArray array];
    }
    return  _array;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

-(void)initOhterButton:(NSString *)title cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destrct otherButtonTitles:(NSArray *)array {
    
    UIView *bgview=[[UIView alloc]init];
    if (title) {
        UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, XHScreenwidth, 24)];
        lable.font=[UIFont systemFontOfSize:14];
        lable.textColor=[UIColor lightGrayColor];
        lable.text=title;
        lable.textAlignment=NSTextAlignmentCenter;
        [bgview addSubview:lable];
        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 25, XHScreenwidth, 1)];
        view.backgroundColor=UIColorWithRGB(242, 242, 242);
        [bgview addSubview:view];
    }
    
    
   
    for (int i=0; i<array.count+1; i++) {
        UIButton *button=[[UIButton alloc] initWithFrame:CGRectMake(0, 25+i*(32+1), XHScreenwidth, 32)];
        UIView *boderview=[[UIView alloc]initWithFrame:CGRectMake(0, 25+i*32, XHScreenwidth, 1)];
        boderview.backgroundColor=UIColorWithRGB(242, 242, 242);
        if (i<array.count) {
            [button setTitle:array[i] forState:UIControlStateNormal];
            [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        }else{
            [button setTitle:destrct forState:UIControlStateNormal];
            [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        }
        [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        button.tag=i;
        [bgview addSubview:boderview];
        [bgview addSubview:button];
        [self.array addObject:button];
    }
    
    CGFloat y=(array.count+1)*33+40;
    
    UIButton *cancel=[[UIButton alloc]initWithFrame:CGRectMake(0, y, XHScreenwidth, 32)];
    [cancel setTitle:cancelButtonTitle forState:UIControlStateNormal];
    [cancel setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [cancel addTarget:self action:@selector(cancelclick) forControlEvents:UIControlEventTouchUpInside];
    [bgview addSubview:cancel];
    CGFloat bgheight=y+32;
    bgview.frame=CGRectMake(0, XHScreenheight-(bgheight), XHScreenwidth, bgheight);
    bgview.backgroundColor=[UIColor whiteColor];
    [self.array addObject:cancel];
    [self.view addSubview:bgview];
}
-(void)showinView:(UIView *)view{
    [view.window addSubview:self.view];
}
-(void)click:(UIButton *)button{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)cancelclick{
    NSLog(@"-----canel");
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
